import com.sun.org.apache.bcel.internal.classfile.InnerClass;

/**
 * 静态内部类实现
 */
public class SingletonDemo04 {
    //设置私有构造方法，禁止外部实例化
    private SingletonDemo04() {
    }

    //设置静态内部类创建对象
    private static class InnerClass {
        private static final SingletonDemo04 instance = new SingletonDemo04();
    }
    //get方法获取内部类的对象
    public static SingletonDemo04 getInstance() {
        return InnerClass.instance;

    }

}

class SingleTonTest04 {
    public static void main(String[] args) {
        SingletonDemo04 instance01 = SingletonDemo04.getInstance();
        SingletonDemo04 instance02 = SingletonDemo04.getInstance();
        System.out.println(instance01 == instance02);  //返回true,代表同一个对象
    }
}
